package PrimeMembers;

public class PrimeMember {
    public static void main(String[] args){
        PrimeMembers1(100);
        PrimeMembers2(100);
    }

    public static void PrimeMembers1(int n){
        for(int i = 2; i <= n; i++){
            boolean isPrime = true;
            for(int j = 2; j * j <= i; j++){
                if(i % j == 0){
                    isPrime = false;
                    break;
                }
            }
            if(isPrime){
                System.out.print(i + " ");
            }
        }
        System.out.println();
    }

    public static void PrimeMembers2(int n){
        boolean[] isPrime = new boolean[n + 1];
        for(int i = 0; i < isPrime.length; i++){
            isPrime[i] = true;
        }

        for(int j = 2; j * j <= n; j++){
            if(isPrime[j]){
                for(int i = j * j; i <= n; i += j){
                    isPrime[i] = false;
                }
            }
        }
        for(int i = 2; i <= n; i++){
            if(isPrime[i]){
                System.out.print(i + " ");
            }
        }
        System.out.println();
    }
}
